﻿using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms.Design;
using ApplicationGenerator.Forms.Actions;

namespace ApplicationGenerator.Forms.Forms
{
    public class ButtonActionTypeEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService edService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            if (edService != null)
            {
                ButtonActionSelect actionForm = new ButtonActionSelect();
                actionForm.SetAction(value as ActionBase);
                if (edService.ShowDialog(actionForm) == System.Windows.Forms.DialogResult.OK)
                {
                    value = actionForm.GetAction();
                }
            }

            return value;
        }
    }
}
